package danny.hoi.exam.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import danny.hoi.exam.dao.UsersDao;
import danny.hoi.exam.domain.Users;
import danny.hoi.exam.service.UsersService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.UUID;

@Service(timeout = 100000)
public class UsersServiceImpl implements UsersService {
    @Autowired
    private UsersDao usersDao;

    @Override
    public PageInfo<Users> findByPages(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Users> list = usersDao.selectByExample(null);
        return new PageInfo<>(list);
    }

    @Override
    public Users findById(String id) {
        return usersDao.selectByPrimaryKey(id);
    }

    @Override
    public List<Users> findAll() {
        return usersDao.selectByExample(null);
    }

    @Override
    public void save(Users users) {
        users.setId(UUID.randomUUID().toString().replaceAll("-", ""));
        usersDao.insertSelective(users);
    }

    @Override
    public void update(Users users) {
        usersDao.updateByPrimaryKey(users);
    }

    @Override
    public void delete(String id) {
        usersDao.deleteByPrimaryKey(id);
    }
}
